
/**
** \file       ast_printclause.c
**
** \brief      this function print the case clause rule
**
** \author     Ben M'rad Hanna, Laterem Hamza, Boillot Ulysse, De Olivera
**             Guillaume and Nguyen Viet Dung
**
** \version    1.0
**
** \date       28 Novembre 2010
**
*/

#include "ast_printer.h"

int	print_caseclause(s_caseclause	*node,
			 int		i,
			 int		fd)
{
  int	pere = i;

  if (node != NULL)
    {
      ++i;
      print_int(i, fd);
      write(fd, " [label = \"case clause\"];\n", 25);
      print_int(pere, fd);
      write(fd, " -> ", 4);
      print_int(i, fd);
      ++i;
      if (node->caseitem != NULL)
	i = print_caseitem(node->caseitem, i, fd);
    }
  return (i);
}

int	print_caseitem(s_caseitem	*node,
		       int		i,
		       int		fd)
{
int	pere = i;

 while (node != NULL)
   {
     ++i;
     print_int(i, fd);
     write(fd, " [label = \"case item\"];\n", 24);
     print_int(pere, fd);
     write(fd, " -> ", 4);
     print_int(i, fd);
     node = node->next;
     if (node->cmpdlist != NULL)
       i = print_cmpdlist(node->cmpdlist, i, fd, i);
   }
 return (i);
}

int	print_dogroup(s_dogroup		*node,
		      int		i,
		      int		fd,
		      int		last)
{
  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"do group\"];\n", 23);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      ++i;
      if (node->todo != NULL)
	last = print_cmpdlist(node->todo, last, fd, last);
    }
  return (last);
}

int	print_else_clause(s_else_clause	*node,
			  int		last,
			  int		fd)
{
  int	i = last;

  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"node else\"];\n", 24);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      if (node->in_if != NULL)
	last = print_cmpdlist(node->in_if, i + 1, fd, last);
      if (node->in_then != NULL)
	last = print_cmpdlist(node->in_then, i + 1, fd, last);
      if (node->in_else != NULL)
	last = print_cmpdlist(node->in_else, i + 1, fd, last);
    }
  return (last);
}
